% 生成exe测试文件
!gcc -O2 main.c -o nextperm_test
!nextperm_test &

% 生成mexw64文件
% 依赖nextperm.c nextperm.h
mex nextperm.c

for n = 1:10
    tic
    nn = 0;
    p = 1:n;
    while 1
        [p, s] = nextperm(p);
        if ~s
            break
        end
        nn = nn+1;
    end
    t = toc;
    fprintf('n=%d; nn=%d; fact=%d (t=%f s)\n', n, nn, factorial(n), t);
end
        